// 计算机部件（产品）
class Computer {
    private String CPU;
    private String RAM;
    private String HDD;
    private String monitor;

    // 使用建造者模式设置各部件
    public void setCPU(String cpu) {
        this.CPU = cpu;
    }
    public void setRAM(String ram) {
        this.RAM = ram;
    }
    public void setHDD(String hdd) {
        this.HDD = hdd;
    }
    public void setMonitor(String monitor) {
        this.monitor = monitor;
    }

    @Override
    public String toString() {
        return "Computer [CPU=" + CPU + ", RAM=" + RAM + ", HDD=" + HDD + ", Monitor=" + monitor + "]";
    }
}

// 抽象建造者
abstract class ComputerBuilder {
    protected Computer computer = new Computer();

    public abstract void buildCPU();
    public abstract void buildRAM();
    public abstract void buildHDD();
    public abstract void buildMonitor();

    public Computer getComputer() {
        return computer;
    }
}

// 具体建造者1
class GamingComputerBuilder extends ComputerBuilder {
    public void buildCPU() {
        computer.setCPU("Intel i9");
    }
    public void buildRAM() {
        computer.setRAM("32GB DDR4");
    }
    public void buildHDD() {
        computer.setHDD("1TB SSD");
    }
    public void buildMonitor() {
        computer.setMonitor("27 inch 4K");
    }
}

// 具体建造者2
class OfficeComputerBuilder extends ComputerBuilder {
    public void buildCPU() {
        computer.setCPU("Intel i5");
    }
    public void buildRAM() {
        computer.setRAM("8GB DDR4");
    }
    public void buildHDD() {
        computer.setHDD("500GB HDD");
    }
    public void buildMonitor() {
        computer.setMonitor("24 inch HD");
    }
}

// 导演类
class Director {
    private ComputerBuilder builder;

    public Director(ComputerBuilder builder) {
        this.builder = builder;
    }

    public Computer construct() {
        builder.buildCPU();
        builder.buildRAM();
        builder.buildHDD();
        builder.buildMonitor();
        return builder.getComputer();
    }
}

// 客户端代码
public class BuilderPatternExample {
    public static void main(String[] args) {
        ComputerBuilder builder = new GamingComputerBuilder();
        Director director = new Director(builder);
        Computer computer = director.construct();
        System.out.println(computer);
    }
}
